import Vue from 'vue'
import App from './App'
import store from './store'
import {
	toast
} from './utils/tools'
import Cache from './utils/cache'
import uView from "@/components/uview-ui";
import minxinsApp from '@/mixins/app'
import MescrollBody from "@/components/mescroll-uni/mescroll-body.vue"
import {
	router,
	RouterMount
} from './router.js'
import routerLink from './js_sdk/uni-simple-router/link.vue'
import request from '@/common/request.js'
import * as navTo from '@/common/navto.js';
Vue.component('mescroll-body', MescrollBody)
Vue.prototype.$toast = toast
Vue.prototype.$Cache = Cache
Vue.config.productionTip = false
Vue.component('RouterLink', routerLink)
Vue.prototype.$baseurl = 'https://miantou.guguan.net/img/';
Vue.use(router)
Vue.mixin(minxinsApp);
Vue.use(uView);
App.mpType = 'app'
const app = new Vue({
	...App,
	store
})
Vue.prototype.$phone = function(num) {
	const phoneStr = num?.toString() || '';
	uni.makePhoneCall({
		phoneNumber: phoneStr
	});
}
Vue.prototype.$copyText = function(text) {
	uni.setClipboardData({
		data: text
	});
}
Vue.prototype.$back = function(num) {
	uni.navigateBack({
		delta: num
	});
}
Vue.prototype.$openLocation = function(latitude, longitude, name, address) {
	console.log("点击跳转");
	uni.openLocation({
		latitude: parseFloat(latitude), //维度
		longitude: parseFloat(longitude), //经度
		name: name, //目的地定位名称
		scale: 15, //缩放比例
		address: address //导航详细地址
	})
}


Vue.prototype.$request = request;
Vue.prototype.$version = '?v=' + Date.now();
Vue.prototype.$navto = navTo;
// 使用全局变量挂载主题
Vue.prototype.$redirectTo = function(url) {
	console.log(url);
	uni.redirectTo({
		url: url
	});
}
Vue.prototype.$switchTab = function(url) {
	uni.switchTab({
		url: url
	});
}
Vue.prototype.$makePhoneCall = function(phoneNumber) {
	phoneNumber = phoneNumber.toString()
	uni.makePhoneCall({
		phoneNumber: '' + phoneNumber //仅为示例
	});
}
Vue.prototype.$strtoarr = function(str, split) {
	var arr = str.split(split);
	return arr;
}

Vue.prototype.$slice = function(str, num) {
	console.log(typeof str);
	let result = str.substring(0, num);
	return result;
}

Vue.prototype.$timestampToTime = function(time) { //时间戳转日期
	let date = new Date(parseInt(time) * 1000);
	let y = date.getFullYear();
	let MM = date.getMonth() + 1;
	MM = MM < 10 ? ('0' + MM) : MM;
	let d = date.getDate();
	d = d < 10 ? ('0' + d) : d;
	let h = date.getHours();
	h = h < 10 ? ('0' + h) : h;
	let m = date.getMinutes();
	m = m < 10 ? ('0' + m) : m;
	let s = date.getSeconds();
	s = s < 10 ? ('0' + s) : s;
	// return y + '-' + MM + '-' + d + ' ' + h + ':' + m + ':' + s;
	return y + '-' + MM + '-' + d;
}


//v1.3.5起 H5端 你应该去除原有的app.$mount();使用路由自带的渲染方式
// #ifdef H5
RouterMount(app, router, '#app');
// #endif

// #ifndef H5
app.$mount(); //为了兼容小程序及app端必须这样写才有效果
// #endif